/*
 * MultiTypeLoadMoreAdapter.java
 * business
 *
 * Created by ChenTao on 2017/3/2.
 *
 * Copyright (c) 2017年 yidiandao. All rights reserved.
 */

package com.yidiandao.business.ui.widget.recyclerview;

import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;

import me.drakeet.multitype.MultiTypeAdapter;

/**
 * 具备加载更多功能的MultiTypeAdapter
 *
 * <p>Created by ChenTao(chentao7v@gmail.com) on 2017/3/2 10:36
 */
public class MultiTypeLoadMoreAdapter extends MultiTypeAdapter {

    private final int TYPE_FOOTER = 20000;

    private View mFooterView;

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int indexViewType) {
        if (indexViewType == TYPE_FOOTER) {
            return new FooterViewHolder(mFooterView);
        }

        return super.onCreateViewHolder(parent, indexViewType);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        if (position > super.getItemCount() - 1) {
            return;
        }

        super.onBindViewHolder(holder, position);
    }

    @Override
    public int getItemViewType(int position) {
        if (position > super.getItemCount() - 1) {
            return TYPE_FOOTER;
        }

        return super.getItemViewType(position);
    }

    @Override
    public int getItemCount() {
        return super.getItemCount() + 1;
    }

    public void addFooterView(View view) {
        mFooterView = view;
    }

    public void removeFooterView(View view) {
    }

    private static class FooterViewHolder extends RecyclerView.ViewHolder {

        public FooterViewHolder(View itemView) {
            super(itemView);
        }
    }
}
